package com.ymatou.iapi.spu.testcase;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.productspu.parameter.CheckSpuCategoryBean;
import com.ymatou.iapi.productspu.service.CheckSpuCategoryCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
/**
*检查类目品牌与SPU匹配关系
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_CheckSpuCategory{
	private static CheckSpuCategoryBean checkspucategoryBean;
	private static CheckSpuCategoryCall checkspucategoryCall;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("检查类目品牌与SPU匹配关系");
	}

	@Before
	public void caseUp() {
		checkspucategoryBean=new CheckSpuCategoryBean();
		checkspucategoryCall=new CheckSpuCategoryCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(checkspucategoryCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_CheckSpuCategory_001() {
		Logger.start(true,"检查类目品牌与SPU匹配关系成功");
		try {
			//可以通过"api/Spu/GetSPUDetail 查询一个正确的数据
			checkspucategoryBean.setSpuId(262936);
			checkspucategoryBean.setThirdCategoryId(1135);
			checkspucategoryCall.setData(checkspucategoryBean);
			checkspucategoryCall.callService();			
			Logger.verifyEquals("200", checkspucategoryCall.getString("Status"), "验证Status");
			Logger.verifyEquals(true,checkspucategoryCall.getJsonObject().get("Result").getAsJsonObject().get("IsMatch").getAsBoolean(),"验证是否匹配");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_CheckSpuCategory_002() {
		Logger.start(true,"不输入spuid失败");
		try {
			checkspucategoryBean.setThirdCategoryId(1135);
			checkspucategoryCall.setData(checkspucategoryBean);
			checkspucategoryCall.callService();			
			Logger.verifyEquals("400", checkspucategoryCall.getString("Status"), "验证Status");
//			Logger.verifyEquals(false,checkspucategoryCall.getJsonObject().get("Result").getAsJsonObject().get("IsMatch").getAsBoolean(),"验证是否匹配");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_CheckSpuCategory_003() {
		Logger.start(true,"不输入ThirdCategoryId失败");
		try {
			checkspucategoryBean.setSpuId(262936);
			checkspucategoryCall.setData(checkspucategoryBean);
			checkspucategoryCall.callService();			
			Logger.verifyEquals("400", checkspucategoryCall.getString("Status"), "验证Status");
//			Logger.verifyEquals(false,checkspucategoryCall.getJsonObject().get("Result").getAsJsonObject().get("IsMatch").getAsBoolean(),"验证是否匹配");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_CheckSpuCategory_004() {
		Logger.start(true,"检查类目品牌与SPU不匹配");
		try {
			checkspucategoryBean.setSpuId(262936);
			checkspucategoryBean.setThirdCategoryId(1136);
			checkspucategoryCall.setData(checkspucategoryBean);
			checkspucategoryCall.callService();			
			Logger.verifyEquals("200", checkspucategoryCall.getString("Status"), "验证Status");
			Logger.verifyEquals(false,checkspucategoryCall.getJsonObject().get("Result").getAsJsonObject().get("IsMatch").getAsBoolean(),"验证是否匹配");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}